<?php
require_once ('library/Model/BaseModel.php');

/**
 *
 * @author Boo
 *        
 */
class Seat extends BaseModel implements IModel{
	/**
	 * @param int $idtrip
	 * @param int $carquantity
	 * return number row insert
	 */
	public function generateSeatByTrip($idtrip,$carquantity){
		$b = 1;
		while ($b<=$carquantity) {
			if ($b==1)
				$sql = 'insert into seat (position,trip,status) value ('.$b.','.$idtrip.',1)';
			else
				$sql = 'insert into seat (position,trip,status) value ('.$b.','.$idtrip.',0)';
			$this->db->execute($sql);
			$b += 1;
		}
	}
	/**
	 * 
	 * @param int $idtrip
	 * return list seat by trip id
	 */
	public function getListseatbytrip($idtrip){
		$sql = 'select * from seat where id = '.$idtrip;
		return $this->db->fetchAll($sql);
	}
	public function deleteListSeatByTrip($tripid){
		$sql = 'delete from seat where trip = '.$tripid;
		$this->db->execute ( $sql );
	}
	
	/**
	 *  @param int $idtrip
	 *  return list seat no check by trip id
	 */
	public function getListSeatNoCheckByTrip($idtrip){
		$sql = 'select * from seat where status = 0 and trip = '.$idtrip;
		return $this->db->fetchAll($sql);
	}
	
	/**
	 * @param $idticket
	 * return listseat trùng route với ticket
	 */
	public function getListSeatNoCheckByTicket($idticket){
		$sql = 'select * 
				from seat as s
				left join ticket as t on t.trip = s.trip  
				where s.status = 0  and t.id ='.$idticket;
		return $this->db->fetchAll($sql);
	}
}

?>